package e.odbo.data.dao.interceptor;

import e.odbo.data.bean.I_AutoGeneratorStringKey;
import e.odbo.data.bean.I_BaseBean;

import java.util.UUID;

public class AutoGeneratorUUIDInterceptor extends AbstractDAOInterceptor{

    @Override
    public boolean beforeInsert(I_BaseBean obj) {
        if (obj.getKey() == null) {
            I_AutoGeneratorStringKey i_GeneratorKey = (I_AutoGeneratorStringKey) obj;
            i_GeneratorKey.setKey(UUID.randomUUID().toString());
        }
        return super.beforeInsert(obj);
    }

    @Override
    public boolean interceptorAble(Class beanClass) {
        return I_AutoGeneratorStringKey.class.isAssignableFrom(beanClass);
    }
}
